package com.suma.platform.core.mq;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

/**
 * 
 * @author suma
 * @date 2018/2/11 下午2:19
 */
@Component
public class Producer {

	@Autowired
	JmsMessagingTemplate jmsTemplate;

	// 发送消息到指定queue，queueName是发送到的队列名，message是待发送的消息
	public void queue(String queueName, final String message) {
		ActiveMQQueue activeMQQueue = new ActiveMQQueue(queueName);
		jmsTemplate.convertAndSend(activeMQQueue, message);
	}

	// 发送消息到指定topic，queueName是发送到的队列名，message是待发送的消息
	public void topic(String queueName, final String message) {
		ActiveMQTopic activeMQTopic = new ActiveMQTopic(queueName);
		jmsTemplate.convertAndSend(activeMQTopic, message);
	}
}
